import 'package:bilibili/util/toast.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:hi_common/util/common_utils.dart';
import 'package:url_launcher/url_launcher.dart';

import '../http/model/benefit_mo.dart';
import 'common_widget.dart';
import 'hi_blur.dart';

class HiBeneFit extends StatelessWidget {
  final List<Benefit> benefitList;

  const HiBeneFit({super.key, required this.benefitList});

  @override
  Widget build(BuildContext context) {
    var width = (MediaQuery.of(context).size.width -
            20 -
            (benefitList.length - 1) * 5) /
        benefitList.length;

    return Column(
      children: [
        buildTitle("增值服务", "购买后登录慕课网再次点击打开查看"),
        const SizedBox(
          height: 10,
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            ...benefitList.map((item) {
              return ClipRRect(
                borderRadius: const BorderRadius.all(Radius.circular(5)),
                child: Container(
                  width: width,
                  height: 60,
                  decoration: const BoxDecoration(color: Colors.redAccent),
                  child: InkWell(
                    onTap: () {
                      var url = item.url;
                      var uri = Uri.tryParse(url);
                      if (uri == null || uri.scheme.isEmpty) {
                        copyToClipboard(url).then((value) {
                          showToast("$value 已帮你拷贝到粘贴板",
                              gravity: ToastGravity.BOTTOM);
                        });
                      } else {
                        launchUrl(uri);
                      }
                    },
                    child: Stack(
                      children: [
                        const HiBlur(),
                        Center(
                          child: Text(
                            item.name,
                            style: const TextStyle(
                                color: Colors.white, fontSize: 14),
                          ),
                        )
                      ],
                    ),
                  ),
                ),
              );
            })
          ],
        )
      ],
    );
  }
}
